package cn.ikun.xk.JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class AppjdbcSelect {
    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/baga?useSSL=false";
        String username = "root";
        String password = "xk20011216";
        Connection connection = DriverManager.getConnection(url, username, password);


        //3、创建陈述句对象
        Statement statement = connection.createStatement();

        //4、执行查询
        String sql = "SELECT id, username FROM `jk_user` ORDER BY id";
        ResultSet set = statement.executeQuery(sql);
        // 5. 获取数据
        while (set.next()) {
            long id = set.getLong(1);
            String name = set.getString(2);
            System.out.println("id=" + id + ", name=" + name);
        }


    }
}
